package utils;

import java.util.LinkedList;
import java.util.List;

import twitter4j.ResponseList;
import twitter4j.Status;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import twitter4j.User;

public class TwitterDAO {
	
	private static TwitterDAO singleton;	
	public synchronized static TwitterDAO fetchDAO(){
		if(singleton == null){
			singleton = new TwitterDAO();
		}
		return singleton;
	}
	
	
	public List<String> fetchTweets(String m) throws TwitterException{
		Twitter twitter = new TwitterFactory().getInstance();
		ResponseList<User> users = twitter.lookupUsers(new String[]{m});
		final List<String> ret = new LinkedList<String>();
		for(User u : users){
			final long id = u.getId();
			ResponseList<Status> tl = twitter.getUserTimeline(id);
			for(Status s : tl){
				ret.add(s.getText());
			}
		}
		return ret;
	}

}
